﻿using AutoMapper;
using Common.Communal;
using ERP.Domain.Scheduling;
using MediatR;
using Scheduling.Api.Write.Application.Command.TeamTypeCommand;
using Scheduling.Repository.Interface;
using Scheduling.Services.TeamTypes;

namespace Scheduling.Api.Write.Application.CommandHandlers.TeamTypeHandler
{
    public class TeamTypeAddCommandHandler : IRequestHandler<TeamTypeAddCommand, ApiResult<int>>
    {
        public TeamTypeAddCommandHandler(ITeamTypeServices teamType,IMapper mapper) 
        {
            TeamType = teamType;
            Mapper = mapper;
        }

        public ITeamTypeServices TeamType { get; }
        public IMapper Mapper { get; }

        public async Task<ApiResult<int>> Handle(TeamTypeAddCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<TeamType>(request);
            return await TeamType.AddTeamType(list);
        }
    }
}
